import { Controller, Get, Inject } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { AppService } from './app.service';
import { Observable } from 'rxjs';

@Controller()
export class AppController {
  constructor(
    private readonly appService: AppService,
    @Inject('testServer') private testServer: ClientProxy,
  ) {}

  @Get('testMsgResponse')
  sendTestMsgResponse(): Observable<any> {
    return this.testServer.send('math:test_send', 'testMsgResponse');
  }

  @Get('testMsgEvent')
  sendTestMsgEvent(): string {
    this.testServer.emit('test_emit', 'testMsgEvent');
    return 'user service event trigger 调用成功，这里返回值主服务其实是接收不到的，因为事件触发是不会返回的，只需要确保子服务触发了事件';
  }
}
